﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyThuVien.Business;

namespace QuanLyThuVien.Presentation
{
    public partial class frmQLDocGia : Form
    {
        public frmQLDocGia()
        {
            InitializeComponent();
        }

        DocGiaBUS DGBus = new DocGiaBUS();
        DocGia dg = new DocGia();

        private void btnNhapDG_Click(object sender, EventArgs e)
        {
            try
            {
                dg.ChucVu = cbChucVu.Text;
                dg.MaDG = txtMaDG.Text;
                dg.TenDG = txtTenDG.Text;
                dg.Lop = txtLop.Text;
                dg.Khoa = txtKhoa.Text;
                dg.NgaySinh = mkNgaySinh.Text;
                dg.GioiTinh = cbGioiTinh.Text;
                dg.GhiChu = txtGhichu.Text;
                DGBus.ThemMoiDG(dg);
                DGBus.LoadLenDG(dgDG);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "QuanLyThuVien");
            }
        }

        private void btnTaoMoiDG_Click(object sender, EventArgs e)
        {
            cbChucVu.Text = "";
            txtMaDG.Text="";
            txtTenDG.Text="";
            txtLop.Text="";
            txtKhoa.Text="";
            mkNgaySinh.Text="";
            cbGioiTinh.Text="";
            txtGhichu.Text="";
        }

        private void btnSuaDG_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có thực sự muốn sửa thông tin độc giả hay không?", "QuanLyThuVien", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                dg.ChucVu = cbChucVu.Text;
                dg.MaDG = txtMaDG.Text;
                dg.TenDG = txtTenDG.Text;
                dg.Lop = txtLop.Text;
                dg.Khoa = txtKhoa.Text;
                dg.NgaySinh = mkNgaySinh.Text;
                dg.GioiTinh = cbGioiTinh.Text;
                dg.GhiChu = txtGhichu.Text;
                DGBus.SuaDG(dg);
                DGBus.LoadLenDG(dgDG);
            }
        }

        private void btnXoaDG_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có thực sự muốn xóa thông tin độc giả hay không?", "QuanLyThuVien", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                dg.MaDG = txtMaDG.Text;
                DGBus.XoaDG(dg.MaDG);
                DGBus.LoadLenDG(dgDG);
            }
        }

        private void cbChucVu_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbChucVu.Text == "Sinh viên")
            {
                txtLop.Enabled = true;
            }
            else
            {
                txtLop.Enabled = false;
            }
        }

        private void frmQLDocGia_Load(object sender, EventArgs e)
        {
            DGBus.LoadLenDG(dgDG);
        }

        private void dgDG_CellClick_1(object sender, DataGridViewCellEventArgs e)
        {
            int a = e.RowIndex;
            txtMaDG.Text = dgDG[0, a].Value.ToString();
            txtTenDG.Text = dgDG[1, a].Value.ToString();
            cbChucVu.Text = dgDG[2, a].Value.ToString();
            txtLop.Text = dgDG[3, a].Value.ToString();
            txtKhoa.Text = dgDG[4, a].Value.ToString();
            mkNgaySinh.Text = dgDG[5, a].Value.ToString();
            cbGioiTinh.Text = dgDG[6, a].Value.ToString();
            txtGhichu.Text = dgDG[7, a].Value.ToString();
        }

    }
}
